package com.swufe.scoresforapp.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageButton;
import android.widget.TextView;

import com.swufe.scoresforapp.R;
import com.swufe.scoresforapp.bean.CompareModel;

import java.util.List;

/**
 * Created by Sophia on 2018/7/14.
 */

public class CompareAdapter extends RecyclerView.Adapter<CompareAdapter.CompareViewHolder>{

    private Context context;
    private List<String> list;
    private OnItemClickListener itemClickListener;


    public CompareAdapter(Context context,List<String> list){
        this.context = context;
        this.list = list;
    }

    @Override
    public CompareViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = View.inflate(context,R.layout.compareview_item,null);
        CompareViewHolder holder = new CompareViewHolder(view);
        return holder;
    }

    @Override
    public void onBindViewHolder(final CompareViewHolder holder, int position) {
        holder.btn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                itemClickListener.onItemClick(holder.itemView,holder.getLayoutPosition());
            }
        });
        holder.text_school.setText(list.get(position));
    }



    @Override
    public int getItemCount() {
        if(list != null){
            return list.size();
        }
        return 0;
    }

    class CompareViewHolder extends RecyclerView.ViewHolder {
        TextView text_school;
        ImageButton btn;
        public CompareViewHolder(View itemView) {
            super(itemView);
            text_school = itemView.findViewById(R.id.compare_school);
            btn = itemView.findViewById(R.id.com_btn_close);
        }

    }

    public interface OnItemClickListener{
        void onItemClick(View view, int position);
    }

    public void setItemClickListener(OnItemClickListener itemClickListener){
        this.itemClickListener = itemClickListener;
    }


}